<?php

namespace app\common\model\Product;

use think\Model;

// 引用软删除
use traits\model\SoftDelete;

class OrderProduct extends Model
{
    // 订单评分表
    protected $table = 'pre_order_product';
	
	// 软删除
	use SoftDelete;
	protected $deleteTime = 'deletetime';
	
	protected $append = [
	    'proimg_cdn', // 多图
	];
	
	public function getProimgCdnAttr($value,$data)
	{
		// $cdn = config('cdn');
	
		$cdn = model('Config')->where(['key' => 'SiteUrl'])->value('value');
	
		$proimg = empty($data['proimg']) ? [] : trim($data['proimg']);
	
		if(empty($proimg))
		{
			// return '暂无评价图片';
			// return $proimg[] = [
			// 	'暂无评论图片'
			// ];
			return $proimg;
		}
	
		//字符串替换
		$proimg = str_replace("uploads/", $cdn."/uploads/", $proimg);
	
		//在转换为数组
		// $list = explode(',', $thumbs);
		$list = json_decode($proimg,true);
	
		if(count($list) > 0)
		{
			return $list;
		}
	
	}

    public function product()
    {
        return $this->belongsTo('app\common\model\Product\Product','proid','id',[])->setEagerlyType(0);
    }

    public function user()
    {
        return $this->belongsTo('app\common\model\User\User','userid','id',[])->setEagerlyType(0);
    }
}
